#include "NativeHooks.h"
#include "VirtualNDK.h"
#include "Modules.h"
#include "Hooker.h"
NativeHooks::NativeHooks(VirtualNDK* vndk, Hooker* hooker):
	vndk(vndk),
	hooker(hooker)
{
	vndk->modules->add_symbol_hook("puts", this->hooker->write_function(hk_puts) + 1);
	vndk->modules->add_symbol_hook("memset", this->hooker->write_function(hk_memset) + 1);
}

NativeHooks::~NativeHooks()
{
}

void NativeHooks::hk_puts(uc_engine * uc)
{
	uint32_t szptr = 0;
	char str[50] = { 0 };
	uc_reg_read(uc, UC_ARM_REG_R0, &szptr);
	uc_mem_read(uc, szptr, str, 30);
	printf("hk_printf:   %s\n", str);
}

void NativeHooks::hk_memset(uc_engine * uc)
{
	uint32_t szptr;
	uint32_t size;
	unsigned char bytes[0x100] = { 0 };
	char str[50] = { 0 };
	uc_reg_read(uc, UC_ARM_REG_R0, &szptr);
	uc_reg_read(uc, UC_ARM_REG_R2, &size);
	uc_mem_write(uc, szptr, bytes, size);
}
